<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
	</body>
	<script>
		const PriceCalculate = (function() {
			/* 售价计算方式 */
			const DiscountMap = {
				minus100_30: function(price) { // 满100减30
					return price - Math.floor(price / 100) * 30
				},
				minus200_80: function(price) { // 满200减80
					return price - Math.floor(price / 200) * 80
				},
				percent80: function(price) { // 8折
					return price * 0.8
				}
			}

			return {
				priceClac: function(discountType, price) {
					return DiscountMap[discountType] && DiscountMap[discountType](price)
				},
				addStrategy: function(discountType, fn) { // 注册新计算方式
					if(DiscountMap[discountType]) return
					DiscountMap[discountType] = fn
				}
			}
		})()

		PriceCalculate.priceClac('minus100_30', 270) // 输出: 210

		PriceCalculate.addStrategy('minus150_40', function(price) {
			return price - Math.floor(price / 150) * 40
		})
		PriceCalculate.priceClac('minus150_40', 270) // 输出: 230
	</script>
</html>